﻿using DevExpress.XtraBars;
using DevExpress.XtraGrid.Views.Base;
using NAGFwk.BL;
using NAGFwk.UI;
using SilkeyERP.BL;

namespace SilkeyERP.UI.Entities.Address
{
    public partial class ContentView : BaseContentDetail
    {
        private readonly IBaseController<Model.Address> _controller = new AddressController();

        public override string ModuleName { get { return "Address"; } }

        public ContentView()
        {
            InitializeComponent();
        }

        public override void ShowModule(bool firstShow)
        {
            base.ShowModule(true);
            MapItLoad(_controller);

        }

        private void bbiDelete_ItemClick(object sender, ItemClickEventArgs e)
        {
            MapItDelete(_controller);
        }

        private void gvBaseContentDetail_RowUpdated(object sender, RowObjectEventArgs e)
        {
            MapItUpdate(e, _controller);
        }

        private void bbiRefresh_ItemClick(object sender, ItemClickEventArgs e)
        {
            MapItRefresh(_controller);
        }

        private void gvBaseContentDetail_ValidateRow(object sender, ValidateRowEventArgs e)
        {

            var myObj = (Model.Address)e.Row;
            if (string.IsNullOrEmpty(myObj.Number.ToString()))
            {
                e.ErrorText = "Numero es Requerido.";
                e.Valid = false;
            }

            if (((Model.Address)e.Row).Order == 0)
            {
                e.ErrorText = "Orden es Requerido";
                e.Valid = false;
            }

            if (string.IsNullOrEmpty(myObj.Street))
            {
                e.ErrorText = "Calle es Requerido.";
                e.Valid = false;
            }
        }
    }
}
